import { key } from "./key";

const ORIGIN_KEY = key;

class ConfigKeyClass {
	usedKey: string[];

	constructor() {
		this.usedKey = key;
	}

	checkCustomKey(customKey: string[]) {
		if (!customKey) {
			return false;
		}
		if (Object.prototype.toString.call(customKey) !== "[object Array]") {
			return false;
		}
		if (customKey.length <= 10) {
			return false;
		}
		customKey.forEach(v => {
			if (typeof v !== "string") {
				return false;
			}
		});
		return true;
	}

	getKey() {
		return this.usedKey;
	}

	getOriginKey() {
		return ORIGIN_KEY;
	}

	setKey(customKey: string[]) {
		if (this.checkCustomKey(customKey)) {
			this.usedKey = customKey;
		}
	}

	resetKey() {
		this.usedKey = ORIGIN_KEY;
	}
}

const configKey = new ConfigKeyClass();

export { key, configKey };
